import Vue from 'vue'
import VueRouter from 'vue-router'

import My from '../views/my/My.vue'
import myPage from "./myPage.js"

import Home from '../views/home/Home.vue'
import homePage from "./homePage.js"

import Service from '../views/service/Service.vue'
import servicePage from "./servicePage.js"

import Shop from '../views/shop/Shop.vue'
import shopPage from "./shopPage.js"

import startOne from '../views/start/one.vue'
import startTwo from '../views/start/two.vue'

Vue.use(VueRouter)

// console.log([...homePage])
const routes = [
  {
    path: "/startTwo",
    component: startTwo,
  },
  {
    path: "/startOne",
    component: startOne,
  },
  {
    path: "/",
    redirect: "/startOne"
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
  },
  ...homePage,

  {
    path: "/service",
    name: "Service",
    component: Service
  },
  ...servicePage,
  {
    path: '/shop',
    name: 'Shop',
    component: Shop
  },
  ...shopPage,
  {
    path: "/my",
    name: "my",
    component: My
  },
  ...myPage,


]

const router = new VueRouter({
    routes
})

// 路由拦截
router.beforeEach((to, from, next) => {
  let token = window.localStorage.getItem("myToken");
  //表示已登录
  if (token) {
    next();
  } else {
    //没有token  表示没有登录
    if (to.path == "/my_login" || to.path == "/zhuce") {
      next();
    } else {
     next({path:"/my_login"});
    }
  }
});

export default router